import React from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, Row, Col, Tabs } from 'antd';
import DeptTree from './components/depttree'
import DeptEdit from './components/deptedit'
import styles from '../Welcome.less'
import { connect } from 'umi';

const { TabPane } = Tabs;

@connect(({ user, Department }) => ({
    currentUser: user.currentUser,
    deptlist: Department.deptlist,
}))
class ViewPage extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            parentNode: {},
            currentNode: {}
        }
    }
    componentDidMount() {
        this.props.dispatch({
            type: 'Department/getAll',
        });
    }
    doSetParent(parentNode) {
        this.setState({ parentNode });
    }
    doSetCurrent(node) {
        this.deptEdit.getData(node);
    }
    freshDept = (e) => {
        if (this.deptTree) {
            this.deptTree.fetchData()
        }
    }
    render() {
        return (
            <PageHeaderWrapper title={false}>
                <Row gutter={[12, 12]}>
                    <Col xs={24} sm={12} md={12} lg={12} xl={6} xxl={6}>
                        <Card>
                            <DeptTree
                                setParent={(para) => this.doSetParent(para)}
                                setCurrent={(para) => this.doSetCurrent(para)}
                                onRef={(ref) => { this.deptTree = ref }} />
                        </Card>
                    </Col>
                    <Col xs={24} sm={12} md={12} lg={12} xl={18} xxl={18}>
                        <Card>
                            <Tabs defaultActiveKey="1">
                                <TabPane tab={<span className={styles.h6}>部门设置</span>} key="1">
                                    <DeptEdit
                                        parentNode={this.state.parentNode}
                                        refresh={this.freshDept} 
                                        onRef={(ref) => { this.deptEdit = ref }}
                                        />
                                </TabPane>
                                
                            </Tabs>

                        </Card>
                    </Col>
                </Row>

            </PageHeaderWrapper>
        )
    }
}
export default ViewPage;